#include "FDEBUtils.h"

FPoint interpolate(const FPoint& p1, const FPoint& p2, double t) {
    return {
        p1.lon + (p2.lon - p1.lon) * t,
        p1.lat + (p2.lat - p1.lat) * t
    };
}

double dotProduct(const Vector2D& v1, const Vector2D& v2) {
    return v1.x * v2.x + v1.y * v2.y;
}

Vector2D vector(const FPoint& p1, const FPoint& p2) {
    return {
        p2.lon - p1.lon,
        p2.lat - p1.lat
    };
}

double magnitude(const Vector2D& v) {
    return std::sqrt(v.x * v.x + v.y * v.y);
}

Vector2D normalize(const Vector2D& v) {
    double mag = magnitude(v);
    return {
        v.x / mag,
        v.y / mag
    };
}

FPoint midpoint(const FPoint& p1, const FPoint& p2) {
    return {
        (p1.lon + p2.lon) / 2.0,
        (p1.lat + p2.lat) / 2.0
    };
}

double distance(const FPoint& p1, const FPoint& p2) {
    double dx = p1.lon - p2.lon;
    double dy = p1.lat - p2.lat;
    return std::sqrt(dx * dx + dy * dy);
}
